﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TB_CS.Rate
{
    public partial class Get_All_Rate : Form
    {
        public Get_All_Rate()
        {
            InitializeComponent();
        }


        private void Get_All_Rate_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Class.SysInfo.WS_TOP.GET_WAIT_RATE(Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
        }

        private void 刷新当前列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            dataGridView1.DataSource = Class.SysInfo.WS_TOP.GET_WAIT_RATE(Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Rate.Rate_Show RRS = new Rate_Show(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
            RRS.Show();
        }

        private void 自动评价前50条好评ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("点击确定开始批量评价，界面会卡主\n请不要重复点击，等待系统自动恢复即可\n订单多的情况下会等很久，请不要关闭界面\n\n确定要自动评价好评订单吗？", "提示", MessageBoxButtons.OKCancel);
            if (dr == DialogResult.OK)
            {
                //用户选择确认的操作
                int j = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    string Tid = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    string Rate_String = Class.SysInfo.WS_TOP.Get_Rate_Feed(Tid,
                       Class.SysInfo.INFO_Seller_Nick.ToString());
                    if (Rate_String.Substring(0, 2) == "1#")
                    {
                        //默认评价

                    }
                    else
                    {
                        string Rate_Type = Rate_String.Split('\n')[1].Split('：')[1].ToString();
                        if (Rate_Type == "好评")
                        {
                            //自动评价
                            Class.SysInfo.WS_TOP.ADD_RATE(Class.SysInfo.INFO_Seller_Nick.ToString(), Tid, Class.SysInfo.Get_Return_Rate().ToString());
                            j++;
                        }
                    }
                }
                MessageBox.Show("成功自动回评价：" + j.ToString() + "条");
                dataGridView1.DataSource = Class.SysInfo.WS_TOP.GET_WAIT_RATE(Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];

            }
            else if (dr == DialogResult.Cancel)
            {
                //用户选择取消的操作
                
            }

            
        }

        private void 自动回评所有默认评价ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("点击确定开始批量评价，界面会卡主\n请不要重复点击，等待系统自动恢复即可\n订单多的情况下会等很久，请不要关闭界面\n\n确定要自动评价默认评价的订单吗？", "提示", MessageBoxButtons.OKCancel);
            if (dr == DialogResult.OK)
            {
                int j = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    string Tid = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    string Rate_String = Class.SysInfo.WS_TOP.Get_Rate_Feed(Tid,
                       Class.SysInfo.INFO_Seller_Nick.ToString());
                    if (Rate_String.Substring(0, 2) == "1#")
                    {
                        //默认评价
                        Class.SysInfo.WS_TOP.ADD_RATE(Class.SysInfo.INFO_Seller_Nick.ToString(), Tid, Class.SysInfo.Get_Return_Rate().ToString());
                        j++;
                    }
                }
                MessageBox.Show("成功自动回评价：" + j.ToString() + "条");
                dataGridView1.DataSource = Class.SysInfo.WS_TOP.GET_WAIT_RATE(Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
            }
            else if (dr == DialogResult.Cancel)
            {
                //用户选择取消的操作

            }
        }

        private void toolStripTextBox1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter)
            {
                //搜索
                dataGridView1.DataSource = Class.SysInfo.WS_TOP.GET_WAIT_RATE_Goods_ID(Class.SysInfo.GET_Seller_Nick().ToString(),toolStripTextBox1.Text.Trim().ToString()).Tables[0];
                toolStripTextBox1.Text = "";
            }
        }
    }
}
